<?
@ob_start("ob_gzhandler");
require_once("db.inc.php");
header('Content-Disposition: attachment; filename="tradelog.csv"');
$sql = "SELECT tradelog.id, tradelog.knownitemsid, knownitems.name, tradelog.quantity, tradelog.price, tradelog.username, tradelog.tradetime, tradelog.Action FROM tradelog,knownitems WHERE tradelog.knownitemsid=knownitems.id AND tradelog.botid=$botid ";
$sql .= "ORDER BY tradelog.id DESC";
$result = mysql_query($sql,$db);
$w = 0;
$v = 0;
$t = "";
$s = "\"";
$t .= "\"id\",\"item name\",\"quantity\",\"price\",\"Total\",\"username\",\"Date\",\"Action\"" . chr(13) . chr(10);
while ($myrow = mysql_fetch_row($result))
{
	if($myrow[7]=="buy" && $myrow[4]>0)
	{
		$v += ($myrow[3]*$myrow[4]);
		$t.= "$s$myrow[0]$s,$s$myrow[2]$s,$s$myrow[3]$s,$s$myrow[4]$s,$s-" . ($myrow[3]*$myrow[4]) . "$s,$s$myrow[5]$s,$s$myrow[6]$s,$s$myrow[7]$s" . chr(13) . chr(10);
	}
	else
	{
		$w += ($myrow[3]*$myrow[4]);
		$t.= "$s$myrow[0]$s,$s$myrow[2]$s,$s$myrow[3]$s,$s$myrow[4]$s,$s" . ($myrow[3]*$myrow[4]) . "$s,$s$myrow[5]$s,$s$myrow[6]$s,$s$myrow[7]$s" . chr(13) . chr(10);
	}
};
echo "\"Total positive\",\"$w\",\"Total negative\",\"$v\"" . chr(13) . chr(10);
echo $t . chr(13) . chr(10);
?>